home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 9.2 KB | 376 lines | [TEXT/CWIE] |
- //============================================================================
- // CDirectoryItem.cp ©1997 Metrowerks Inc. All rights reserved
- // Original author: John C. Daub
- //============================================================================
- // A concrete LOutlineItem for items of type "directory".
-
- #include "CDirectoryItem.h"
- #include "CFileItem.h"
- #include "SendFinderOpen.h"
- #include <LOutlineItem.h>
- #include <LOutlineTable.h>
- #include <UGAColorRamp.h>
-
- #include <Gestalt.h>
-
- #include "OutlineTablePrefix.h"
-
- extern Handle gOnIcon;
- extern Handle gOffIcon;
-
- #include "GetFileIcon.h"
-
- /* !!!!!! Add new gestalt selector names here !!!!!! */
-
- StringPtr gGestaltNames[] =
- {
- "\pDrag Manager"
- };
-
- CDirectoryItem::CDirectoryItem( int nameId, OSType selector, Uint32 subValues )
- {
- // store the FSSpec for the file associated with this item.
-
- // Note that even tho we are storing data for an item within
- // the outline item, this doesn't provide any sort of persistant
- // storage of data within the table (see comments in COutlineTable's
- // ctor about mTableStorage).
-
- // The reason for this is how the outline table class deals with
- // expansion and collapsing of hierarchical nodes... when you expand
- // the item's ExpandSelf method is called. And as things are expanded
- // and such, items are created.. as collapsed, they are deleted. So
- // there is no persistance of the outline items and their stored data.
-
- // This is also why you might have a deep expansion of nested hierarchies
- // in the table, but you collapse a top-level parent, reexpand that and
- // the expand/nesting hierarchy is not maintained... everything was
- // deleted and has to be recreated.
-
- fSelector = selector;
- fSubValues = subValues;
- fNameId = nameId;
- fState = false;
- }
-
-
- // dtor
-
- CDirectoryItem::~CDirectoryItem()
- {
- }
-
- // determine what it is that we're to draw in a given column
-
- void
- CDirectoryItem::GetDrawContentsSelf(
- const STableCell& inCell,
- SOutlineDrawContents& ioDrawContents)
- {
-
- switch (inCell.col)
- {
- default:
- {
- ioDrawContents.outShowSelection = true;
- ioDrawContents.outHasIcon = false; //true;
- ioDrawContents.outIconSuite = nil; //(fState? gOnIcon : gOffIcon);
- ioDrawContents.outTextTraits.style |= bold;
-
- if (fNameId >= 0)
- {
- LString::CopyPStr(gGestaltNames[fNameId], ioDrawContents.outTextString);
- }
- else
- {
- Str255 tmpName;
- LString::FourCharCodeToPStr(fSelector, tmpName);
- LString::CopyPStr(tmpName, ioDrawContents.outTextString);
- }
-
- break;
- }
- #if 000000
- case 2:
- {
- ioDrawContents.outShowSelection = true;
- ioDrawContents.outHasIcon = false;
- ioDrawContents.outTextTraits.style = 0;
-
- LString::CopyPStr("\p-", ioDrawContents.outTextString);
-
- break;
- }
- #endif
- }
- }
-
-
- // by default, rows are not expanders.. but since this is a directory
- // and we're showing hierarchy, of course we need to be able to expand.
- // So we must make sure the table is aware of that fact.
-
- Boolean
- CDirectoryItem::CanExpand() const
- {
- return true;
- }
-
-
- // just to be cute, draw an adornment of a gray background
-
- void
- CDirectoryItem::DrawRowAdornments(
- const Rect& inLocalRowRect )
- {
- ShadeRow(UGAColorRamp::GetColor(2), inLocalRowRect);
- }
-
-
- // this is the magic of what we do when someone tries to
- // expand this item. We create outline items for all possible subitems.
- // We do not need to destruct these (in CollapseSelf) as that is
- // handled for us automatically.. see comments in LOutlineItem.cp for
- // more information
-
- void
- CDirectoryItem::ExpandSelf()
- {
-
- LOutlineItem* theItem = nil;
- LOutlineItem* lastItem = nil;
- UInt32 i;
-
- for (i = 0; i < 32; i++)
- {
- if (fSubValues & (1L << i))
- {
- // it's a gestalt item
-
- theItem = new CFileItem( -1, fSelector, i );
- ThrowIfNil_(theItem);
-
- // and insert it at the end of the table
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
- }
- }
-
- #if 000000
- /****** Duplicate a block like */
-
- // it's a gestalt item
-
- theItem = new CFileItem( 0, gestaltDragMgrAttr, gestaltDragMgrPresent );
- ThrowIfNil_(theItem);
-
- // and insert it at the end of the table
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
-
- /****** this for an item */
-
- // it's a gestalt item
-
- theItem = new CFileItem( 1, gestaltDragMgrAttr, gestaltDragMgrFloatingWind );
- ThrowIfNil_(theItem);
-
- // and insert it at the end of the table
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
-
- // it's a gestalt item
-
- theItem = new CFileItem( 2, gestaltDragMgrAttr, gestaltPPCDragLibPresent );
- ThrowIfNil_(theItem);
-
- // and insert it at the end of the table
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
-
- // it's a gestalt item
-
- theItem = new CFileItem( 3, gestaltDragMgrAttr, gestaltDragMgrHasImageSupport );
- ThrowIfNil_(theItem);
-
- // and insert it at the end of the table
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
-
- // it's a gestalt item
-
- theItem = new CFileItem( 4, gestaltDragMgrAttr, gestaltCanStartDragInFloatWindow );
- ThrowIfNil_(theItem);
-
- // and insert it at the end of the table
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
- }
- #endif
-
- /* !!!!!! Add new gestalt items names here !!!!!! */
-
- #if 000000
-
- CInfoPBRec folderInfo;
- Str31 dirFileName;
- LString::CopyPStr( mFileSpec.name, dirFileName, sizeof(Str31) );
-
- // find the info for this directory (mostly to get it's dirID)
- folderInfo.hFileInfo.ioCompletion = nil;
- folderInfo.hFileInfo.ioNamePtr = dirFileName;
- folderInfo.hFileInfo.ioVRefNum = mFileSpec.vRefNum;
- folderInfo.hFileInfo.ioFDirIndex = 0;
- folderInfo.hFileInfo.ioDirID = mFileSpec.parID;
-
- ThrowIfOSErr_(::PBGetCatInfoSync( &folderInfo ));
-
- LOutlineItem *theItem = nil;
- Int16 index = 1;
- LOutlineItem *lastItem = nil;
-
- while ( true ) {
-
- // and recurse through this folder to list its contents
-
- CInfoPBRec fileInfo;
- Str31 fileName;
-
- fileInfo.hFileInfo.ioCompletion = nil;
- fileInfo.hFileInfo.ioNamePtr = fileName;
- fileInfo.hFileInfo.ioVRefNum = folderInfo.hFileInfo.ioVRefNum;
- fileInfo.hFileInfo.ioFDirIndex = index++;
- fileInfo.hFileInfo.ioDirID = folderInfo.hFileInfo.ioDirID;
-
- OSErr err = ::PBGetCatInfoSync( &fileInfo );
- if ( err != noErr )
- break;
-
- // we ignore invis stuff
- if ( fileInfo.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible )
- continue;
-
- // make an FSSpec for the file
-
- FSSpec theSpec;
-
- ThrowIfOSErr_(::FSMakeFSSpec( folderInfo.hFileInfo.ioVRefNum,
- folderInfo.hFileInfo.ioDirID,
- fileName,
- &theSpec ));
-
- // make an outline item based upon a directory or file
-
- if ( fileInfo.hFileInfo.ioFlAttrib & ioDirMask )
- {
- // it's a directory
-
- theItem = new CDirectoryItem( theSpec );
- ThrowIfNil_(theItem);
- }
- else
- {
- // it's a file
-
- theItem = new CFileItem( theSpec );
- ThrowIfNil_(theItem);
- }
-
- // and insert it at the end
-
- mOutlineTable->InsertItem( theItem, this, lastItem );
- lastItem = theItem;
- }
- #endif
- }
-
- // send an open document AppleEvent to the Finder to open this
- // given directory
-
- void
- CDirectoryItem::DoubleClick(
- const STableCell& /* inCell */,
- const SMouseDownEvent& /* inMouseDown */,
- const SOutlineDrawContents& /* inDrawContents */,
- Boolean /* inHitText */)
- {
- #if 000000
- ThrowIfOSErr_(SendFinderOpenAE(&mFileSpec));
- #endif
- }
-
- // ---------------------------------------------------------------------------
- // * TrackContentClick [protected]
- // ---------------------------------------------------------------------------
- // Called by ClickCell whenever a mouse-down event occurs within
- // the contents (icon or text) of this cell. Selects or deselects this
- // cell as appropriate and tests for dragging or double-clicking.
-
- void
- CDirectoryItem::TrackContentClick(
- const STableCell& /*inCell*/,
- const SMouseDownEvent& inMouseDown,
- const SOutlineDrawContents& /*inDrawContents*/,
- Boolean /*inHitText*/)
- {
- #if 000000
- // If item isn't selected, try to select it now.
-
- Boolean wasSelected = mOutlineTable->CellIsSelected(inCell);
- if (!wasSelected) {
- if (!(inMouseDown.macEvent.modifiers & shiftKey))
- mOutlineTable->UnselectAllCells();
- mOutlineTable->SelectCell(inCell);
- mOutlineTable->UpdatePort();
- }
- #endif
- // See if mouse moves. If it does, track a drag from it
-
- if (::StillDown() && ::WaitMouseMoved(inMouseDown.macEvent.where)) {
- // TrackDrag(inCell, inMouseDown, inDrawContents);
- return;
- }
-
- #if 000000
- // Mouse didn't move, see if this was a double-click.
-
- if (LPane::GetClickCount() > 1) {
- DoubleClick(inCell, inMouseDown, inDrawContents, inHitText);
- return;
- }
-
- // If none of the above, and shift key was down, deselect this cell.
-
- if (wasSelected && (inMouseDown.macEvent.modifiers & shiftKey)) {
- mOutlineTable->UnselectCell(inCell);
- mOutlineTable->UpdatePort();
- return;
- }
-
- // Simple click and item is still selected, call it a single click.
-
- if (mOutlineTable->CellIsSelected(inCell)) {
- SingleClick(inCell, inMouseDown, inDrawContents, inHitText);
- return;
- }
- #endif
-
- SetState((fState ? false : true));
- return;
- }
-
- void CDirectoryItem::SetState(bool state)
- {
- fState = state;
- mOutlineTable->Refresh();
-
- /* !!!!!! Handle group selection/deselection here !!!!!! */
-
- return;
- }